﻿namespace PrismEx.UnityExtensions
{
    using Microsoft.Practices.Prism.Events;
    using Microsoft.Practices.Unity;
    using Microsoft.Practices.Unity.ObjectBuilder;

    public class AutoSubscribeUnityContainerExtension : UnityContainerExtension
    {
        private readonly IEventAggregator eventAggregator;

        public AutoSubscribeUnityContainerExtension(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;
        }

        protected override void Initialize()
        {
            var strategy = new AutoSubscribeBuilderStrategy(eventAggregator);

            Context.Strategies.Add(strategy, UnityBuildStage.PostInitialization);
        }
    }
}
